﻿using System;
using System.Collections.Generic;
using System.Linq;
using DevExpress.CodeRush.StructuralParser;
using CR.StyleCop.Utils;
using CR.StyleCop.Extensions;

namespace CR.StyleCop.Documentation {

    /// <summary>
    /// 
    /// </summary>
    class ElementsMustBeDocumentedSearcher : BaseStyleCopIssueSearcher<IClassElement, IConstructorInitializerElement, IDelegateElement, IEnumElement, IEventElement, IInterfaceElement, IMethodElement, IPropertyElement, IStructElement> {
        public override IEnumerable<StyleCopIssue> FindIssues(IEnumerable<IElement> elements) {
            // TODO (fen): How do I find finalizers and indexers. I also have to check if DocComment is empty.

            // We have to convert all elements to CodeElement's to be able to access the DocComment property
            // If the DocComment is null there is no comment available and it should be marked as an issue.
            return elements.SelectLanguageElement<CodeElement>().Where(ce => ce.DocComment == null || Empty(ce.DocComment))
                .Select(ce => new StyleCopIssue {
                    Element = ce,
                    IssueDescription = "Code element is missing a documentation header."
                });

        }

        private bool Empty(XmlDocComment docComment) {
            return false;
        }
    }
}
